package com.azt.novel.book.service.impl;


import com.azt.novel.book.dto.resp.BookChapterRespDto;
import com.azt.novel.book.dto.resp.BookContentAboutRespDto;
import com.azt.novel.book.dto.resp.BookInfoRespDto;
import com.azt.novel.book.manager.cache.BookChapterCacheManager;
import com.azt.novel.book.manager.cache.BookContentCacheManager;
import com.azt.novel.book.manager.cache.BookInfoCacheManager;
import com.azt.novel.book.service.IBookContentService;
import com.azt.novel.common.resp.RestResp;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 小说内容 服务实现类
 * </p>
 *
 * @author azt
 * @since 2023-12-02
 */
@Service
public class BookContentServiceImpl implements IBookContentService {


    @Resource
    private BookChapterCacheManager bookChapterCacheManager;

    @Resource
    private BookInfoCacheManager bookInfoCacheManager;

    @Resource
    private BookContentCacheManager bookContentCacheManager;

    /**
     *
     * (chapter)bookChapterDto-->bookInfoDto
     * @param chapterId
     * @return
     */
    @Override
    public RestResp<BookContentAboutRespDto> getBookContent(Long chapterId) {
        //获取bookChapterDto
        BookChapterRespDto bookChapterRespDto = bookChapterCacheManager.getChapterById(chapterId);
        //bookChapterRespDto

        //获取bookInfoDto
        BookInfoRespDto bookInfoRespDto = bookInfoCacheManager.getBookById(bookChapterRespDto.getBookId());
        //bookInfoRespDto

        //获取bookContent
        String bookContent = bookContentCacheManager.getBookContent(chapterId);

        //整合到BookContentDto中
        return RestResp.ok(BookContentAboutRespDto.builder()
                .bookInfo(bookInfoRespDto)
                .chapterInfo(bookChapterRespDto)
                .bookContent(bookContent)
                .build());
    }
}
